/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.dianlan.processor.business;

import com.alibaba.fastjson2.JSON;
import info.peigen.hotpot.component.gateway.dianlan.annotations.DianlanProtocolParse;
import info.peigen.hotpot.component.gateway.dianlan.facade.command.order.DianlanStubSpearHeadResponseOrder;
import info.peigen.hotpot.component.gateway.dianlan.processor.AbstractDianlanProcessor;
import info.peigen.hotpot.component.gateway.dianlan.protocol.Dianlan;
import info.peigen.hotpot.component.gateway.dianlan.protocol.active.DianlanSpearHeadResponse;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.StateMachineEnum;
import org.smartboot.socket.transport.AioSession;

/**
 * <b>(DianlanStubSpearHeadResponseProcessor)</b>
 * 电桩待机
 *
 * @author czj
 * @version 1.0.0
 * @since 2023/2/1
 */
@Component("dianlanStubSpearHeadResponseProcessor")
@Slf4j
public class DianlanStubSpearHeadResponseProcessor<T> extends AbstractDianlanProcessor implements MessageProcessor<T> {

    @Override
    public void process(AioSession session, Object obj) {
        Dianlan                  dianlan  = (Dianlan) obj;
        DianlanSpearHeadResponse response = DianlanProtocolParse.deserialization(dianlan.getData(), DianlanSpearHeadResponse.class);
        log.info("Data:" + JSON.toJSONString(response));
        DianlanStubSpearHeadResponseOrder order = DianlanStubSpearHeadResponseOrder.builder()
                .stubNo(response.getStubNo())
                .chargingPortNo(response.getChargingPortNo())
                .lock(response.getLock())
                .push(response.getPush())
                .reset(response.getReset())
                .push(response.getPush()).build();
        dianlanServiceFacade.spearHeadResponse(order);
    }

    @Override
    public void stateEvent(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
        MessageProcessor.super.stateEvent(session, stateMachineEnum, throwable);
    }
}